// 例子27

var pattern = /Java/g;
var text = 'JavaScript is more fun than Java!';
var result;
while((result = pattern.exec(text)) != null) {
		alert('Matched "' + result[0] + '"' + ' at position ' + result.index + ';next search begins at ' + pattern.lastIndex);
}
// 弹窗结果：
// 第一次：Matched "Java" at position 0;next search begins at 4
// 第二次：Matched "Java" at position 28;next search begins at 32